namespace InventoryManagement
{
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.ComponentModel;
	using System.Data;
	using System.Data.SqlClient;
	using System.Text;
	
	
	public class Vendor : BaseTable
	{
		
		#region Static SQL String Members
		/// <remarks>This field represents the full SELECT string for the table Vendor, with the WHERE clause.</remarks>
		internal static string _SQL_Select = "SELECT [ID], [Title], [Name], [IsDeleted] FROM [dbo].[Vendor] WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the full SELECT string for the table Vendor, with the WHERE clause.</remarks>
		internal static string _SQL_SelectByParam = @"SELECT [ID], [Title], [Name], [IsDeleted] FROM [dbo].[Vendor] WHERE isnull(convert(varchar(36),[ID]),'true')=isnull(convert(varchar(36),@ID),isnull(convert(varchar(36),[ID]),'true')) AND isnull(convert(varchar,[Title]),'true')=isnull(convert(varchar,@Title),isnull(convert(varchar,[Title]),'true')) AND isnull(convert(varchar,[Name]),'true')=isnull(convert(varchar,@Name),isnull(convert(varchar,[Name]),'true')) AND isnull(convert(varchar,[IsDeleted]),'true')=isnull(convert(varchar,@IsDeleted),isnull(convert(varchar,[IsDeleted]),'true')) ";
		
		/// <remarks>This field represents the full INSERT INTO string for the table Vendor.</remarks>
		internal static string _SQL_Insert = "INSERT INTO [dbo].[Vendor] ([ID], [Title], [Name], [IsDeleted]) VALUES(@ID, @Title, @Name, @IsDeleted) ";
		
		/// <remarks>This field represents the full UPDATE string for the table Vendor, with the WHERE clause.</remarks>
		internal static string _SQL_Update = "UPDATE [dbo].[Vendor] SET [ID] = @ID, [Title] = @Title, [Name] = @Name, [IsDeleted] = @IsDeleted WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the DELETE string for the table Vendor, with the WHERE clause.</remarks>
		internal static string _SQL_Delete = "DELETE FROM [dbo].[Vendor] WHERE [ID]=@ID ";
		#endregion
		
		#region Tables Members
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _ID;
		
		[DisplayName("ID")]
		[Category("Primary Key")]
		public System.Nullable<System.Guid> ID
		{
			get
			{
				try
				{
					return _ID;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID", err);
				}
			}
			set
			{
				try
				{
					_ID = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _Title;
		
		[DisplayName("Title")]
		[Category("Column")]
		public string Title
		{
			get
			{
				try
				{
					return _Title;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Title", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_Title = value;
					}
					else
					{
						throw new OverflowException("Error setting Title, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Title", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _Name;
		
		[DisplayName("Name")]
		[Category("Column")]
		public string Name
		{
			get
			{
				try
				{
					return _Name;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Name", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_Name = value;
					}
					else
					{
						throw new OverflowException("Error setting Name, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Name", err);
				}
			}
		}
		
		/// <remarks>SQL Type:bit - </remarks>
		private System.Nullable<bool> _IsDeleted;
		
		[DisplayName("Is Deleted")]
		[Category("Column")]
		public System.Nullable<bool> IsDeleted
		{
			get
			{
				try
				{
					return _IsDeleted;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting IsDeleted", err);
				}
			}
			set
			{
				try
				{
					_IsDeleted = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting IsDeleted", err);
				}
			}
		}
		#endregion
		
		#region Public Methods
		public void Select()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Vendor._SQL_Select;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataReader rs = Com.ExecuteReader();
				while(rs.Read())
				{
					AddFromRecordSet(rs);
				}
				rs.Close();
				Conn.Close();
				rs.Dispose();
				Com.Dispose();
				Conn.Dispose();
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public System.Data.DataTable SelectByParam()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Vendor._SQL_SelectByParam;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataAdapter objDataAdapter = new SqlDataAdapter(Com);
				DataTable objDataTable = new DataTable();
				objDataAdapter.Fill(objDataTable);
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return objDataTable;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Insert()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Vendor._SQL_Insert;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Update()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Vendor._SQL_Update;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Delete()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Vendor._SQL_Delete;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public string[] GetSqlCommandStrings()
		{
			try
			{
				string[] CommStr = new string[4];
				CommStr[0] = "SELECT [ID], [Title], [Name], [IsDeleted] FROM [dbo].[Vendor] WHERE [ID] = " + _ID + "";
				CommStr[1] = "INSERT INTO [dbo].[Vendor] ([ID], [Title], [Name], [IsDeleted]) VALUES(" + _ID + ", '" + _Title.Replace("'","''") + "', '" + _Name.Replace("'","''") + "', " + _IsDeleted + ")";
				CommStr[2] = "UPDATE [dbo].[Vendor] SET [Title] = '" + _Title.Replace("'","''") + "' ,[Name] = '" + _Name.Replace("'","''") + "' ,[IsDeleted] = " + _IsDeleted + " WHERE [ID] = " + _ID + "";
				CommStr[3] = "DELETE FROM [dbo].[Vendor] WHERE [ID] = " + _ID + "";
				return CommStr;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		#endregion
		
		#region Private Methods
		private void AddFromRecordSet(SqlDataReader rs)
		{
			try
			{
				// if value from the recordset, to the ID field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ID")) == false))
				{
					ID = rs.GetGuid(rs.GetOrdinal("ID"));
				}
				// if value from the recordset, to the Title field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Title")) == false))
				{
					Title = rs.GetString(rs.GetOrdinal("Title"));
				}
				// if value from the recordset, to the Name field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Name")) == false))
				{
					Name = rs.GetString(rs.GetOrdinal("Name"));
				}
				// if value from the recordset, to the IsDeleted field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("IsDeleted")) == false))
				{
					IsDeleted = rs.GetBoolean(rs.GetOrdinal("IsDeleted"));
				}
			}
			catch (SqlException sqlExc)
			{
				throw sqlExc;
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		
		private SqlParameter[] GetSqlParameters()
		{
			List<SqlParameter> SqlParmColl = new List<SqlParameter>();
			try
			{
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ID", ID, SqlDbType.UniqueIdentifier));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Title", Title, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Name", Name, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@IsDeleted", IsDeleted, SqlDbType.Bit));
				return SqlParmColl.ToArray();
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		#endregion
	}
	
	public class VendorCollection : System.Collections.CollectionBase
	{
		
		[Description("Adds a new Vendor to the collection.")]
		public int Add(Vendor item)
		{
			int newindex = List.Add(item);
			return newindex;
		}
		
		[Description("Removes a Vendor from the collection.")]
		public void Remove(Vendor item)
		{
			List.Remove(item);
		}
		
		[Description("Inserts an Vendor into the collection at the specified index.")]
		public void Insert(int index, Vendor item)
		{
			List.Insert(index, item);
		}
		
		[Description("Returns the index value of the Vendor class in the collection.")]
		public int IndexOf(Vendor item)
		{
			return List.IndexOf(item);
		}
		
		[Description("Returns true if the Vendor class is present in the collection.")]
		public bool Contains(Vendor item)
		{
			return List.Contains(item);
		}
	}
	
	public enum Vendor_Fields
	{
		
		ID,
		
		Title,
		
		Name,
		
		IsDeleted,
	}
}
